﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using DMC.Database;

namespace prjLichSuXemBienBanXetDuyet
{
    public class clsLichSuXemBienBanXetDuyet
    {
        public DataTable dt = new DataTable();
        public string strconnection = "";
        public string MaDVHC="";
        public string MaHoSoCapGCNOld = "";
        public string MaHoSoCapGCN="";
        public string ID = "";
        public string HoSoCapGCNold
        {
            get { return MaHoSoCapGCNOld; }
            set { MaHoSoCapGCNOld = value; }
        }
        public string id
        {
            get { return ID; }
            set { ID = value; }
        }
        public string DonViHanhChinh
        {
            get { return MaDVHC; }
            set { MaDVHC = value; }
        }
        public string HoSoCapGCN
        {
            get { return MaHoSoCapGCN; }
            set { MaHoSoCapGCN = value; }
        }
        public  string Connection
        {
            get { return strconnection; }
            set { strconnection = value; }
        }       
        public DataTable getLichSuBienBanXetDuyet(ref DataTable dt)
        {
            string[] para = {"@MaDonViHanhChinh","@MaHoSoCapGCN"};
            string[] value = {MaDVHC,MaHoSoCapGCN};
            //DataTable dt = new DataTable();
            clsDatabase cls = new clsDatabase();
            cls.Connection = strconnection;
            cls.OpenConnection();            
            //cls.getValue(dt,"spSelectLichSuXemBienBanXetDuyet", para, value);
            cls.getValue(ref dt, "CT_SelectLichSuXemBienBanXetDuyet", para, value);
            //dgvLichSu.DataSource = dt;
            return dt;
        }       
        public DataTable Select_Data(string sp, string[] Values, string[] paras)
        {
            string strError = "";
            DataTable MyTable = new DataTable();
            try
            {
                //Khoi tao doi tuong DMC.clsDatabase
                clsDatabase Database = new clsDatabase();
                Database.Connection = Connection;
                //SqlConnection conn = new SqlConnection();
                if (Database.OpenConnection()==true)
                {
                    //Chắc chắn rằng mảng giá trị truyền vào tương đương với mảng tham biến
                    if ((paras.Length != Values.Length))
                    {
                        return null;
                    }
                    //Gọi phương thức GetValue của đối tượng clsDatabase
                    Database.getValue(ref MyTable, sp, paras, Values);
                    Database.CloseConnection();
                }
            }
            catch (Exception ex)
            {
                strError = ex.Message;
            }
            return MyTable;
        }
        public DataTable SelectDVHC()
        {
            DataTable dt = new DataTable();
            string strError = "";
            try
            {
                string[] Values = { MaDVHC };
                string[] Param = { "@MaDVHC" };
                dt = Select_Data("spSelectHuyenTinh", Values, Param);
                strError = "";
            }
            catch (Exception ex)
            {
                strError = ex.Message;
            }
            return dt;
        }
        public DataTable SelectInBienBanXetDuyetHoSoCapGCN()
        {
            DataTable dt = new DataTable();
            string strError = "";
            try
            {
                string[] Values = { ID,MaHoSoCapGCN};
                string[] Param = { "@ID","@MaHoSoCapGCN" };
                dt = Select_Data("CT_spInBienBanXetDuyetHoSoCapGCN", Values, Param);
                strError = "";
            }
            catch (Exception ex)
            {
                strError = ex.Message;
            }
            return dt;
        }        
        public DataTable SelectInChuSuDung()
        {
            DataTable dt = new DataTable();
            string strError = "";
            try
            {
                string[] Values = { ID,MaHoSoCapGCN };
                string[] Param = { "@ID","@MaHoSoCapGCN" };
                dt = Select_Data("CT_sp_SelectInPhieuChuSuDung", Values, Param);
                strError = "";
            }
            catch (Exception ex)
            {
                strError = ex.Message;
            }
            return dt;
        }       
        public DataTable SelectInHoiDongXetDuyet()
        {
            DataTable dt = new DataTable();
            string strError = "";
            try
            {
                string[] Values = { ID, MaHoSoCapGCN };
                string[] Param = { "@ID", "@MaHoSoCapGCN" };
                dt = Select_Data("CT_sp_SelectInHoiDongXetDuyet", Values, Param);
                strError = "";
            }
            catch (Exception ex)
            {
                strError = ex.Message;
            }
            return dt;
        }
        public DataTable SelectHoiDongXetDuyet()
        {
            DataTable dt = new DataTable();
            string strError = "";
            try
            {
                string[] Values = { MaHoSoCapGCNOld };
                string[] Para = { "@MaHoSoCapGCN" };
                dt = Select_Data("sp_SelectInHoiDongXetDuyet", Values, Para);
                strError = "";
            }
            catch (Exception ex)
            {
                strError = ex.Message;
            }
            return dt;
        }

        public DataTable SelectHoSoXetDuyet()
        {
            DataTable dt = new DataTable();
            string strError = "";
            try
            {
                string[] Values = { MaHoSoCapGCNOld };
                string[] Para = { "@MaHoSoCapGCN" };
                dt = Select_Data("sp_SelectHoSoKyThuatBienBanXetDuyet", Values, Para);
                strError = "";
            }
            catch (Exception ex)
            {
                strError = ex.Message;
            }
            return dt;
        }
        public DataTable SelectTaiSanXetDuyet()
        {
            DataTable dt = new DataTable();
            string strError = "";
            try
            {
                string[] Values = { MaHoSoCapGCNOld };
                string[] Para = { "@MaHoSoCapGCN" };
                dt = Select_Data("sp_SelectTaiSanBienBanXetDuyet", Values, Para);
                strError = "";
            }
            catch (Exception ex)
            {
                strError = ex.Message;
            }
            return dt;
        }
        public DataTable SelectBienBanXetDuyet()
        {
            DataTable dt = new DataTable();
            string strError = "";
            try
            {
                string[] Values = { MaHoSoCapGCNOld };
                string[] Para = { "@MaHoSoCapGCN" };
                dt = Select_Data("spInBienBanXetDuyetHoSoCapGCN", Values, Para);
                strError = "";
            }
            catch (Exception ex)
            {
                strError = ex.Message;
            }
            return dt;
        }
        public DataTable SelectChuSuDung()
        {
            DataTable dt = new DataTable();
            string strError = "";
            try
            {
                string[] Values = { MaHoSoCapGCNOld };
                string[] Para = { "@MaHoSoCapGCN" };
                dt = Select_Data("sp_SelectInPhieuChuSuDung", Values, Para);
                strError = "";
            }
            catch (Exception ex)
            {
                strError = ex.Message;
            }
            return dt;
        }
    }
}
